/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.feiyue;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.Handler;
import android.text.Editable;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import com.feiyue.basic.reader.util.CustomToast;
import com.feiyue.basic.server.db.BookCollectDBHandler;
import com.feiyue.basic.server.net.NovelInfo;
import com.feiyue.basic.server.parser.Book;
import com.feiyue.helper.BookListAdapter;
//import com.searchbook.Config;
//import com.searchbook.KeywordsActivity;
//import com.searchbook.keywordsflow.KeywordsFlow;
import com.umeng.analytics.MobclickAgent;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class BookSearchActivity extends Activity implements
		View.OnClickListener {
	private List<Book> booklist;
	private Context context;
	private EditText editText;
	private Handler handler;
	protected InputMethodManager imm;
	protected String keywords;
//	private KeywordsFlow keywordsFlow;
	protected ArrayList<HashMap<String, Object>> listItem;
	protected BookListAdapter listItemAdapter;
	protected ListView listview;
	public List<Book> localbooklist;
	private MessageReceiver messageReceiver;
	private LinearLayout morebooks;
	private Myrunnable myrunnable;
	private View.OnKeyListener onKey = new View.OnKeyListener() {
		public boolean onKey(View paramView, int paramInt,
				KeyEvent paramKeyEvent) {
			if (paramInt == 66) {
//				BookSearchActivity.this.whatwedo.setVisibility(8);
//				if (BookSearchActivity.this.thread2getnewbookisrunning) {
//					BookSearchActivity.this.imm.hideSoftInputFromWindow(
//							BookSearchActivity.this.editText.getWindowToken(),
//							0);
//					return true;
//				}
//				BookSearchActivity.this.thread2getnewbookisrunning = true;
//				BookSearchActivity.this.keywords = BookSearchActivity.this.editText
//						.getText().toString();
//				if ((BookSearchActivity.this.keywords == null)
//						|| (BookSearchActivity.this.keywords.equals(""))) {
//					new CustomToast(BookSearchActivity.this.context).show(
//							"您没有输入关键词", 300);
//					BookSearchActivity.this.thread2getnewbookisrunning = false;
//					return true;
//				}
//				BookSearchActivity.this.keywordsFlow.setVisibility(8);
//				BookSearchActivity.this.listview.setVisibility(0);
//				BookSearchActivity.this.morebooks.setVisibility(0);
//				BookSearchActivity.this.booklist.clear();
//				BookSearchActivity.this.listItem.clear();
//				BookSearchActivity.this.listItemAdapter.notifyDataSetChanged();
//				BookSearchActivity.this.imm.hideSoftInputFromWindow(
//						BookSearchActivity.this.editText.getWindowToken(), 0);
//				new BookSearchActivity.MyThread(BookSearchActivity.this, null)
//						.start();
//				return true;
			}
			return false;
		}
	};
	private ImageView searchaction;
	public boolean thread2getnewbookisrunning = false;
	private TextView whatwedo;

	private View.OnClickListener getsearchactiononclick() {
		return new View.OnClickListener() {
			public void onClick(View paramView) {
//				BookSearchActivity.this.whatwedo.setVisibility(8);
//				if (BookSearchActivity.this.thread2getnewbookisrunning) {
//					BookSearchActivity.this.imm.hideSoftInputFromWindow(
//							BookSearchActivity.this.editText.getWindowToken(),
//							0);
//					return;
//				}
//				BookSearchActivity.this.thread2getnewbookisrunning = true;
//				BookSearchActivity.this.keywords = BookSearchActivity.this.editText
//						.getText().toString();
//				if ((BookSearchActivity.this.keywords == null)
//						|| (BookSearchActivity.this.keywords.equals(""))) {
//					new CustomToast(BookSearchActivity.this.context).show(
//							"您没有输入关键词", 300);
//					BookSearchActivity.this.thread2getnewbookisrunning = false;
//					return;
//				}
//				BookSearchActivity.this.keywordsFlow.setVisibility(8);
//				BookSearchActivity.this.listview.setVisibility(0);
//				BookSearchActivity.this.morebooks.setVisibility(0);
//				BookSearchActivity.this.booklist.clear();
//				BookSearchActivity.this.listItem.clear();
//				BookSearchActivity.this.listItemAdapter.notifyDataSetChanged();
//				BookSearchActivity.this.imm.hideSoftInputFromWindow(
//						BookSearchActivity.this.editText.getWindowToken(), 0);
//				new BookSearchActivity.MyThread(BookSearchActivity.this, null)
//						.start();
			}
		};
	}

	public void load() {
//		this.listview.setVisibility(0);
//		this.booklist.addAll(this.localbooklist);
//		int i = this.localbooklist.size();
//		for (int j = 0;; ++j) {
//			if (j >= i) {
//				this.listItemAdapter.notifyDataSetChanged();
//				return;
//			}
//			HashMap localHashMap = new HashMap();
//			localHashMap.put("ItemTile",
//					((Book) this.localbooklist.get(j)).getName());
//			localHashMap.put("ItemAuthor",
//					"作者:" + ((Book) this.localbooklist.get(j)).getAuthor());
//			localHashMap.put("ItemIntroduction", "介绍:"
//					+ ((Book) this.localbooklist.get(j)).getIntroduction());
//			this.listItem.add(localHashMap);
//		}
	}

	public void onClick(View paramView) {
//		if (!(paramView instanceof TextView))
//			return;
//		this.keywords = ((TextView) paramView).getText().toString();
//		this.keywordsFlow.setVisibility(8);
//		this.listview.setVisibility(0);
//		this.morebooks.setVisibility(0);
//		new MyThread(null).start();
	}

	public void onCreate(Bundle paramBundle) {
		super.onCreate(paramBundle);
		setContentView(2130903045);
//		this.keywordsFlow = ((KeywordsFlow) findViewById(2131099775));
//		this.context = getApplicationContext();
//		this.editText = ((EditText) findViewById(2131099773));
//		this.searchaction = ((ImageView) findViewById(2131099774));
//		this.searchaction.setOnClickListener(getsearchactiononclick());
//		this.morebooks = ((LinearLayout) findViewById(2131099690));
//		this.whatwedo = ((TextView) findViewById(2131099777));
//		this.listview = ((ListView) findViewById(2131099776));
//		this.booklist = new ArrayList();
//		this.localbooklist = new ArrayList();
//		this.listItem = new ArrayList();
//		this.listItemAdapter = new BookListAdapter(this.context, this.listItem,
//				2130903043, new String[] { "ItemTile", "ItemAuthor",
//						"ItemIntroduction" }, new int[] { 2131099695,
//						2131099696, 2131099697 }, this.booklist);
//		this.listview.setAdapter(this.listItemAdapter);
//		this.listview
//				.setOnItemClickListener(new AdapterView.OnItemClickListener() {
//					public void onItemClick(AdapterView<?> paramAdapterView,
//							View paramView, int paramInt, long paramLong) {
//						BookSearchActivity.this.setTitle("点击第" + paramInt
//								+ "个项目");
//						Intent localIntent = new Intent(BookSearchActivity.this
//								.getApplicationContext(),
//								BookBriefActivity.class);
//						localIntent.putExtra("categoryname", "");
//						localIntent.putExtra("categoryid",
//								((Book) BookSearchActivity.this.booklist
//										.get(paramInt)).getCategoryId());
//						localIntent.putExtra("bookname",
//								((Book) BookSearchActivity.this.booklist
//										.get(paramInt)).getName());
//						localIntent.putExtra("bookid",
//								((Book) BookSearchActivity.this.booklist
//										.get(paramInt)).getId());
//						localIntent.putExtra("author",
//								((Book) BookSearchActivity.this.booklist
//										.get(paramInt)).getAuthor());
//						localIntent.putExtra("introduction",
//								((Book) BookSearchActivity.this.booklist
//										.get(paramInt)).getIntroduction());
//						localIntent.putExtra("issuestate",
//								((Book) BookSearchActivity.this.booklist
//										.get(paramInt)).getIssuestate());
//						localIntent.putExtra("coverid",
//								((Book) BookSearchActivity.this.booklist
//										.get(paramInt)).getCoverid());
//						localIntent.putExtra("coverAddr",
//								((Book) BookSearchActivity.this.booklist
//										.get(paramInt)).getCoverAddr());
//						BookSearchActivity.this.startActivity(localIntent);
//					}
//				});
//		this.morebooks.setVisibility(8);
//		this.listview.setVisibility(8);
//		this.myrunnable = new Myrunnable(null);
//		this.handler = new Handler();
//		this.imm = ((InputMethodManager) getApplicationContext()
//				.getSystemService("input_method"));
//		this.editText.setOnKeyListener(this.onKey);
//		this.messageReceiver = new MessageReceiver();
//		IntentFilter localIntentFilter = new IntentFilter(
//				"MESSAGERECEIVER_BOOKID");
//		registerReceiver(this.messageReceiver, localIntentFilter);
//		KeywordsActivity.launchsearch(this);
//		Config.keywordsFlow.setOnItemClickListener(this);
//		this.keywordsFlow.setVisibility(0);
//		this.listview.setVisibility(8);
	}

	protected void onDestroy() {
		unregisterReceiver(this.messageReceiver);
		super.onDestroy();
	}

	protected void onPause() {
		this.whatwedo.setVisibility(8);
		this.imm.hideSoftInputFromWindow(this.editText.getWindowToken(), 0);
		super.onPause();
		MobclickAgent.onPause(this);
	}

	protected void onResume() {
		super.onResume();
		MobclickAgent.onResume(this);
	}

	public class MessageReceiver extends BroadcastReceiver {
		public void onReceive(Context paramContext, Intent paramIntent) {
			try {
				BookCollectDBHandler localBookCollectDBHandler = new BookCollectDBHandler(
						paramContext);
				BookSearchActivity.this.listItemAdapter
						.setCollectbooklist(localBookCollectDBHandler
								.getBookList(paramContext));
				localBookCollectDBHandler.destroy();
				BookSearchActivity.this.listItemAdapter.notifyDataSetChanged();
				return;
			} catch (Exception localException) {
			}
		}
	}

	private class MyThread extends Thread {
		public void run() {
//			BookSearchActivity.this.localbooklist = NovelInfo
//					.getsearchBookList(
//							BookSearchActivity.this.context,
//							NovelInfo
//									.getUrl2searchBooklist(BookSearchActivity.this.keywords
//											.replace(" ", "_")));
//			if ((BookSearchActivity.this.localbooklist != null)
//					&& (BookSearchActivity.this.localbooklist.size() != 0)) {
//				BookSearchActivity.this.myrunnable.setisload(true);
//				BookSearchActivity.this.myrunnable.setistips(false);
//			}
//			while (true) {
//				BookSearchActivity.this.handler
//						.post(BookSearchActivity.this.myrunnable);
//				super.run();
//				return;
//				BookSearchActivity.this.myrunnable.setistips(true);
//			}
		}
	}

	private class Myrunnable implements Runnable {
		public boolean isload = false;
		private boolean showtips = false;

		private void reset() {
			this.isload = false;
			this.showtips = false;
		}

		public void run() {
//			if (this.isload)
//				BookSearchActivity.this.load();
//			if (this.showtips)
//				BookSearchActivity.this.whatwedo.setVisibility(0);
//			while (true) {
//				BookSearchActivity.this.morebooks.setVisibility(8);
//				reset();
//				BookSearchActivity.this.thread2getnewbookisrunning = false;
//				return;
//				BookSearchActivity.this.whatwedo.setVisibility(8);
//			}
		}

		public void setisload(boolean paramBoolean) {
			this.isload = paramBoolean;
		}

		public void setistips(boolean paramBoolean) {
			this.showtips = paramBoolean;
		}
	}
}